package dev;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Sys {

	
	public static void process() throws IOException{
		List<String> command = new ArrayList<String>();
	    command.add(System.getenv("windir") +"\\system32\\"+"tree.com");
	    command.add("/A");

	    ProcessBuilder builder = new ProcessBuilder(command);
	    Map<String, String> environ = builder.environment();
	    builder.directory(new File(System.getenv("temp")));

	    System.out.println("Directory : " + System.getenv("temp") );
	    final Process process = builder.start();
	    InputStream is = process.getInputStream();
	    InputStreamReader isr = new InputStreamReader(is);
	    BufferedReader br = new BufferedReader(isr);
	    String line;
	    while ((line = br.readLine()) != null) {
	      System.out.println(line);
	    }
	    System.out.println("Program terminated!");
	}
	
	public static void cmd() throws IOException{
		String line;
		OutputStream stdin = null;
		InputStream stderr = null;
		InputStream stdout = null;

		// launch EXE and grab stdin/stdout and stderr
		Process process = Runtime.getRuntime().exec ("/folder/exec.exe");
		stdin = process.getOutputStream ();
		stderr = process.getErrorStream ();
		stdout = process.getInputStream ();

		// "write" the parms into stdin
		line = "param1" + "\n";   
		stdin.write(line.getBytes() );
		stdin.flush();

		line = "param2" + "\n";
		stdin.write(line.getBytes() );
		stdin.flush();

		line = "param3" + "\n";
		stdin.write(line.getBytes() );
		stdin.flush();

		stdin.close();

		// clean up if any output in stdout
		BufferedReader brCleanUp =  new BufferedReader (new InputStreamReader (stdout));
		while ((line = brCleanUp.readLine ()) != null) {
			//System.out.println ("[Stdout] " + line);
		}
		brCleanUp.close();

		// clean up if any output in stderr
		brCleanUp = new BufferedReader (new InputStreamReader (stderr));
		while ((line = brCleanUp.readLine ()) != null) {
			//System.out.println ("[Stderr] " + line);
		}
		brCleanUp.close();
	}

	
	public static void launch(String fileName) throws IOException{
		File file = new File(fileName);
		Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL "
				+ file.getAbsolutePath());
	}



	public static void main(String[] args) {
		try {
			launch("C:\\Documents and Settings\\Administrator\\Desktop\\de_cautat.txt");
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
